package com.qiqv.controller;

import com.qiqv.dto.QiQvResult;
import com.qiqv.dto.Song;
import com.qiqv.exception.ApplicationException;
import com.qiqv.service.SongService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hjr
 * @version 1.0
 * @date 2023/2/14 10:20
 */
@RestController
@RequestMapping("song")
public class SongController {
    
    @Resource
    private SongService songService;

    /**
     * 获取所有可用歌曲
     * @return
     */
    @PostMapping("getAllSongs")
    public QiQvResult getAllSongs(){
        List<Song> songList = songService.getAllSongs();
        return QiQvResult.OK(songList);
    }

    /**
     * 根据歌名获取歌曲
     * @return
     */
    @PostMapping("findSongByName")
    public QiQvResult findSongByName(Song song){
        if(StringUtils.isBlank(song.getName())){
            throw new ApplicationException("歌名不能为空");
        }
        Song songList = songService.findSongByName(song.getName());
        return QiQvResult.OK(songList);
    }
    
    
}
